package widget;

import javax.swing.*;
import java.util.HashMap;

/**
 * Created by LLAP on 2017/12/13.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
public class TTextArea extends TComponent {
    public TTextArea(String name, String comment, boolean required) {
        super(name, new JTextArea(), comment, required);
    }
    public TTextArea(String name, boolean required) {
        this(name, name, required);
    }
    public TTextArea(String name, String comment) {
        this(name, comment, false);
    }
    public TTextArea(String name) {
        this(name, name);
    }

    @Override
    public void clear() {
        ((JTextArea)field).setText("");
    }

    @Override
    public HashMap<String, Object> getData() {
        if (required && ((JTextArea)field).getText().equals("")) {
            throw new IllegalArgumentException(this.comment + "不能为空");
        }
        return new HashMap<String, Object>() {{
            put(name, ((JTextArea)field).getText());
        }};
    }
}